#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include "./ftrace_hook_lib.h"



extern int fh_install_hook(struct ftrace_hook *hook);
extern void fh_remove_hook(struct ftrace_hook *hook);


/* 指向被hook函数的指针类型 */
static asmlinkage long (*orig_do_fork)(unsigned long, unsigned long, unsigned long, int __user *, int __user *);


static long fh_do_fork(unsigned long clone_flags,
					unsigned long stack_start,
					unsigned long stack_size,
					int __user *parent_tidptr,
					int __user *child_tidptr)
{
	long ret;

  pr_info("<%s>: current_task:%s, current_task.pid:%d, clone_flags = 0x%lx, stack_start = 0x%lx "
					"stack_size = 0x%lx\n", __func__, current->comm, current->pid, clone_flags, stack_start, stack_size);

	ret = orig_do_fork(clone_flags, stack_start, stack_size, parent_tidptr, child_tidptr);

	pr_info("execve() returns:%ld\n", ret);


	return ret;
}




static struct ftrace_hook hooked_functions[] = {
	{
		.name = "_do_fork",
		.function = fh_do_fork,
		.original = &orig_do_fork,
	},
};


static int ftrace_hook_init(void)
{

	fh_install_hook(&(hooked_functions[0]));
	

	return 0;
}


static void ftrace_hook_exit(void)
{
	
	fh_remove_hook(&(hooked_functions[0]));

	return ;
}


module_init(ftrace_hook_init);
module_exit(ftrace_hook_exit);


MODULE_LICENSE("GPL");

